Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_zones & create_zone REST API endpints #56

Merged
merged 6 commits into from
Aug 4, 2017
Merged

Conversation

ice9js
Copy link
Member

@ice9js ice9js commented Aug 3, 2017

This PR adds get_zones & create_zones endpoints to the REST API.

Endpoints

  • GET /zoninator/v1/zones ( get a list with all zones )
  • POST /zoniantor/v1/zones ( create a new zone )

Other

Changed permissions for add_post_to_zone to update as it falls under editing a zone rather than creating one.

@ice9js ice9js requested a review from pgk August 3, 2017 11:00
Copy link
Contributor

@pgk pgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really like it overall!! 💯 Some minor stylistic/formatting changes and we are good to go!! :)

@@ -1,9 +1,8 @@
<?php
/**
* @packae Zoninator/Rest
* @package Zoninator/Rest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this!

$this->translations = array(
self::ZONE_NOT_FOUND => __( 'Zone not found', 'zoninator' ),
self::INVALID_POST_ID => __( 'Invalid post id', 'zoninator' ),
self::INVALID_ZONE_ID => __( 'Zone not found', 'zoninator' ),
self::ZONE_ID_POST_ID_REQUIRED => __( 'post id and zone id required', 'zoninator' ),
);

$this->add_route( 'zones' )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great form here!

) );
}

return new WP_REST_Response( $results, 200 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can also do return $this->ok( $results );


$zone = $this->instance->get_zone( $result[ 'term_id' ] );

return $this->created( $zone );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice created usage! :)

$slug = $this->_get_param( $request, 'slug', '' );
$description = $this->_get_param( $request, 'description', '', 'strip_tags' );

$result = $this->instance->insert_zone( $slug, $name, array( 'description' => $description ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Better if we split this into multiple lines (standard php practice on arrays with string keys, leave a comma in the array's end. Like so:

$result = $this->instance->insert_zone( $slug, $name, array( 
    'description' => $description, 
) );

@@ -479,6 +547,11 @@ public function strip_slashes( $item ) {
return stripslashes( $item );
}

public function strip_tags( $item ) {
// see https://github.com/WP-API/WP-API/issues/1520 on why we do not use stripslashes directly
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update comment to be about strip_tags :)

@pgk pgk merged commit 0f0785b into add/rest-api Aug 4, 2017
@pgk pgk deleted the update/rest-api branch August 4, 2017 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants